In continuation of thread posted before as below: |
Re: Array of Skip lists But since you probably need to find the values for a specific module, you can use a Skip of Skips instead of an Array of Skips. Regards, Mathias Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |
Re: Array of Skip lists
Some thoughts and recommendations: string eValue eValue = O_obj.attr ""
(Note the "" after the 'O_obj.attr' to force the result being a string. Honestly, I don't know what happens in your case. If the attribute 'attr' is of type integer, then eValue would be of the same type (I guess). Sometime later, when you loop through the Skip lists and have to retrieve the key, you will not know which type to cast and will be in trouble. Safer to stick to strings (letting aside the famous string table, but that's a different story)
int n = 2
Skip s[n] = {}
s[0] = createString()
put(s[0], "a", "a")
put(s[0], "b", "b")
s[1] = createString()
put(s[1], "a", "c")
put(s[1], "b", "d")
// ...
int i
Skip t
for i in 0:n-1 do
{
t = s[i]
string x
for x in t do print x " "
delete t // Don't forget to delete the Skip list to avoid memory leaks
}
6) If the number of elements is really unknown, I personally prefer Skip lists of Skip lists:
Skip sOuter = create()
int n = 0
Skip sInner = null
sInner = createString()
put(sInner, "a", "a")
put(sInner, "b", "b")
put(sOuter, n++, sInner)
sInner = createString()
put(sInner, "a", "c")
put(sInner, "b", "d")
put(sOuter, n++, sInner)
// ...
int i
for i in 0:n-1 do
{
if (find(sOuter,i, sInner))
{
string x
for x in sInner do print x " "
delete sInner // Don't forget to delete the Skip list to avoid memory leaks
}
}
delete sOuter // don't forget to delete the "outer" SKip list as well
7) You don't have to "delete(S_attValueListMod ...; put(S_attValueListMod ...". Since v9.3, the "put" perm has a boolean flag which which you can overwrite entries:
put(S_attValueListMod,eValue,++existIValue,true)
Regards,
|
Re: Array of Skip lists I have implemented skip of skips as per the instructions.But the error "key used outside SkipList do loop" is occuring. I have attached my code. unable to solve the problem. Is there any way to traverse through the skiplist like in array A[1], A[2]... Thanks & Regards, Anurag Attachments attachment_14891502_New1.dxl |
Re: Array of Skip lists PJAnurag - Thu Sep 27 09:03:15 EDT 2012 I see at line 53 you loop through your sInner skip and line 55 you use the "key" command correctly. But I see at line 60 you are modifying variable "sInner" within the loop starting at line 53. That's like doing this:
I'm not following this well but suspect that at lines 50/53/55 you need to use a different Skip variable, perhaps "sOuter". That would make sense if the Skip stored at location 0 was some form of index into the Skips that start at location 1. Deleting sInner at line 80 looks REAL bad; even if you were to 1st remove the skip from the Array first. I notice you fail to declare "sInner". Gives me Heebee Jeebees. -Louie |
Re: Array of Skip lists PJAnurag - Thu Sep 27 09:03:15 EDT 2012 Looking at your code I guess you want to look whether an attribute value of the fist Module appears in any of the other Modules. The code for doing that would look like the following (note that I couldn't check if it really runs without DXL errors, as you must have defined and populated somewhere above
void refreshSkipAttrList(){}
int selModCountModule selMod[]
Skip S_attValueListMod
DBE lstDspAttr
Now the actual code would be
/*-------------------------------- **** --------------------------------
frequency
-------------------------------- **** -------------------------------- */
void frequency(string attr) {
int ii
string eValue
int existIValue
int ReqCount=0
Object O_obj
AttrDef A_ad
Skip sInner
bool acr
acr = true
refreshSkipAttrList()
for(ii=0;ii<selModCount;ii++) //calculation for number of Modules
{// for all selected Module
ReqCount = 0
A_ad = find(selMod[ii],attr)
if(!null A_ad)
{
sInner = createString()
for O_obj in selMod[ii] do { //calcualte the count of attribute values for attribute in each module
ReqCount++
if (!canRead(O_obj))
{
acr = false
continue
}
if (isDeleted O_obj){continue}
if (table O_obj){continue}
if (row O_obj){continue}
eValue = O_obj.attr""
if (eValue == "") {continue}
if(find(sInner, eValue, existIValue)) {++existIValue}
else {existIValue = 1}
put(sInner, eValue,existIValue,true)
}
}
put(sInner, "Total_" name selMod[ii], ReqCount)
put(S_attValueListMod,ii,sInner)
}
empty lstDspAttr
int ind, index = 0
// Below is an example for simply looping over all Skip lists:
/*
for sInner in S_attValueListMod do
{
ind = (int key S_attValueListMod)
print "\n" (name selMod[ind]) ": "
for existIValue in sInner do
{
eValue = (string key sInner)
print "\n\t" eValue ": " existIValue ""
}
}
*/
// From your code I guess you want to raise a flag when a given attribute
// value from the first Module appears in any of the other Modules, if that's
// the case, then you would do the following. Note that you need another
// Skip list which contains the respective values from the first Module
Skip sFirstModule
if (find(S_attValueListMod,0,sFirstModule))
{
string sAttValue
int iValue
for iValue in sFirstModule do
{
sAttValue = (string key sFirstModule)
// Now look for that attribute value in the other Skip lists
flag = false
for sInner in S_attValueListMod do
{
ind = (int key S_attValueListMod)
if (ind == 0){continue} // Skip the first Module
if (find(sInner, sAttValue)){flag = true}
else {flag = false; break} // Do you really want to break here?
// not found in second Module == no search in other Modules
}
if(flag)
{
insert(lstDspAttr,index++,sAttValue,iconNone)
}
}
}
// Delete all Skip lists
for sInner in S_attValueListMod do {delete sInner}
delete S_attValueListMod
} /* frequency */
As Louie already pointed out, your initial mistake was that you first used 'sInner' to contain the attribute values from the first Module (Line 53), then looped through 'sInner' (Line 56), but in that loop used the same variable name to assign it to each Skip list in 'S_attValueListMod' (Line 62). If you want to compare all Modules to the first, you have to reserve one additional Skip list, 'sFirstModule' in the code above.
|
Re: Array of Skip lists |
Re: Array of Skip lists PJAnurag - Fri Sep 28 03:48:28 EDT 2012
From your other post here http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14891843 I now understand that you want to calculate the frequency of occurence of any attribute value over all selected Modules. This means that there still is a fundamental mistake in your approach: you are only reporting on attribute values which occur in the first Module and in any other Module (the second Module, actually, due to the "break" command).
Skip sAllAttrValues = createString
for sInner in S_attValueListMod do
{
ind = (int key S_attValueListMod)
for existIValue in sInner do
{
eValue = (string key sInner)
put(sAllAttrValues, eValue , eValue) // This gives you a list
// of all attribute values
// in any of the Modules
}
}
string sAttValue
for sAttValue in sAllAttrValues do {
insert(lstDspAttr,index++,sAttValue,iconNone)
}
|